package com.vcc.msc.sbs;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.util.Log;
import android.view.KeyEvent;

public class ParentActivity extends Activity {
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		Log.d(this.getClass().getName(), "onKeyDown..");
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Log.d(this.getClass().getName(), "back..." + isTaskRoot()
					+ isChild());

			if (isTaskRoot() || !moveTaskToBack(true)) {
				AlertDialog.Builder builder = new AlertDialog.Builder(this);
				builder.setMessage("Are you sure you want to exit?")
						.setCancelable(false)
						.setPositiveButton("Yes",
								new DialogInterface.OnClickListener() {
									public void onClick(DialogInterface dialog,
											int id) {
										ParentActivity.this.finish();
									}
								})
						.setNegativeButton("No",
								new DialogInterface.OnClickListener() {
									public void onClick(DialogInterface dialog,
											int id) {
										dialog.cancel();
									}
								}).show();
			}

			return true;
		}
		return super.onKeyDown(keyCode, event);
	}
}
